package org.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.demo.entity.Community;
import org.demo.entity.Housewear;
import org.demo.mapper.CommunityMapper;
import org.demo.mapper.HousewearMapper;
import org.demo.service.ICommunityService;
import org.demo.service.IHousewearService;
import org.demo.service.IOrderIdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CommunityServiceImpl extends ServiceImpl<CommunityMapper, Community> implements ICommunityService {
    @Autowired
    private CommunityMapper communityMapper;
    @Autowired
    private IOrderIdService orderIdService;


    @Override
    public void add(Community community) {
        String id = orderIdService.getId("COMM");
        community.setId(id);
        save(community);
    }

    @Override
    public List<Community> list(Community community) {
        if (community==null){
            List<Community> communitylist=communityMapper.selectList(null);
            return communitylist;
        }else if (community.getId()!=null){
            List<Community> communitylist=lambdaQuery().eq(Community::getId,community.getId()).list();
            return communitylist;
        }else{
            List<Community> communitylist=lambdaQuery().eq(Community::getId,community.getName()).list();
            return communitylist;
        }
    }

    @Override
    public void update(Community community) {
        lambdaUpdate().eq(Community::getId,community.getId()).update();
    }

    @Override
    public void delete(String id) {
        communityMapper.deleteById(id);
    }
}
